package com.shengyin.ec.service.permission;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.permission.AccountDao;
import com.shengyin.ec.model.entity.Goods;
import com.shengyin.ec.model.entity.Users;

@Service(value="accountService")
public class AccountServiceImpl implements AccountService {

	@Autowired
	AccountDao accountDao;
	
	
	@Override
	public void createUsers(Users account) {
		accountDao.save(account);		
	}

	@Override
	public void deleteUsers(Users account) {
		Users users=accountDao.get(account.getId());
		accountDao.delete(users);
		
	}

	@Override
	public void deleteUsersById(long id) {
		accountDao.deleteByKey(id);		
	}

	@Override
	public void modifyUsers(Users account) {
		
		Users users=accountDao.get(account.getId());
		try {
			BeanUtils.copyProperties(users, account);
			accountDao.update(users);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}		
	}

	@Override
	public Users getUsersById(long id) {
		return accountDao.get(id);
	}

	@Override
	public List<Users> getUsersList() {
		return accountDao.loadAll();
	}

	@Override
	public List<Users> getUsersList(int start, int end) {
		return accountDao.getUsersList(start,end);
	}

	@Override
	public List<Users> getUsersListByKeyword(String keyword, int start, int end) {
		return accountDao.getUsersListByKeyword(keyword, start, end);
	}

	@Override
	public void deleteSelectedUsers(Long[] ids) {
		accountDao.deleteSelectedUsers(ids);		
	}

	@Override
	public Long getTotal() {
		return  accountDao.getTotal();		
	}

	@Override
	public Users getUsersByUsername(String username) {
		return accountDao.getUsersByUsername(username);
	}

}
